using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace LifeChess.GamePlay.Test
{
    public class ChessLifeInfoPanel : MonoBehaviour
    {
        public float moveSpeed = 2.0f;
        
        [SerializeField] private bool isShowPanel = false;

        private Text infoText;
        private Image infoPanelBackground;
        private RectTransform rectTransform;

        private void Awake()
        {
            infoText = transform.GetChild(0).GetComponent<Text>();
            infoPanelBackground = GetComponent<Image>();
            rectTransform = GetComponent<RectTransform>();
        }

        public void ShowInfoPanel(string info)
        {
            isShowPanel = true;
            infoText.text = info;
            infoPanelBackground.color = new Color(1, 1, 1, 0.5f);
        }

        public void HideInfoPanel()
        {
            isShowPanel = false;
            infoText.text = "";
            infoPanelBackground.color = new Color(1, 1, 1, 0);
        }

        private void Update()
        {
            if (isShowPanel)
            {
                FollowMouseArrow();
            }
        }

        private void FollowMouseArrow()
        {
            if (Input.mousePosition.y >= 360.0f)
            {
                Vector2 newPivot = rectTransform.pivot;
                newPivot.y = 1;
                rectTransform.pivot = newPivot;
            }
            else
            {
                Vector2 newPivot = rectTransform.pivot;
                newPivot.y = 0;
                rectTransform.pivot = newPivot;
            }

            if (Input.mousePosition.x >= 1200.0f)
            {
                Vector2 newPivot = rectTransform.pivot;
                newPivot.x = 1;
                rectTransform.pivot = newPivot;
            }
            else
            {
                Vector2 newPivot = rectTransform.pivot;
                newPivot.x = 0;
                rectTransform.pivot = newPivot;
            }

            transform.position += moveSpeed * Time.deltaTime * (Input.mousePosition - transform.position);
            Debug.Log(Input.mousePosition);
        }
    }
}